package models;

import play.db.jpa.*;
import play.data.validation.*;
import javax.persistence.*;

/**
 * The user entity class. Contains attributes describing a (business) user (e.g. name) and
 * its login information (username, password).
 * A user is associated with an address and a category (e.g. restaurant, pub).
 * 
 */
@Entity
public class User extends Model {
	
	@Required
	@MaxSize(15)
	@MinSize(4)
	@Match(value = "^\\w*$", message = "user.username.invalid")
	@Unique(message = "user.username.exists")
	public String username;

	@Required(message = "validation.user.password")
	@MaxSize(15)
	@MinSize(5)
	public String password;

	@Required(message = "validation.user.name")
	@MaxSize(100)
	public String name;

	@Required(message = "validation.user.firstname")
	@MaxSize(100)
	public String firstName;

	@Required(message = "validation.user.lastname")
	@MaxSize(100)
	public String lastName;

	@Required(message = "validation.user.email")
	@MaxSize(100)
	@Email
	@Unique(message = "user.email.exists")
	public String emailId;

	@MaxSize(300)
	public String description;

	@OneToOne(cascade = CascadeType.ALL, targetEntity = Address.class)
	public Address address;

	@OneToOne(cascade = CascadeType.ALL, targetEntity = Category.class)
	public Category category;
	
	public User(String username, String password, String name, String firstName, String lastName, String emailId, String description, Address address, Category category) {
		this.username = username;
		this.password = password;
		this.name = name;
		this.firstName = firstName;
		this.lastName = lastName;
		this.emailId = emailId;
		this.description = description;
		this.address = address;
		this.category = category;
	}
	
	public User() {}
	
}
